package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * 新增菜品
     *
     * @param dish
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish (id, name, category_id, price, image, description, status, create_time, update_time, create_user, update_user) " + "values (#{id},#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser});")
    void insert(Dish dish);


    /**
     * 分页查询
     *
     * @param
     * @return
     */
    Page<Dish> PageQuery(Dish dish);


    /**
     * 批量删除菜品
     *
     * @param ids
     * @return
     */
    void deleteBatch(List<Integer> ids);

    /**
     * 根据id查找菜品
     *
     * @param id
     * @return
     */
    DishVO findById(Integer id);


    /**
     * 修改菜品
     * @param dish
     * @return
     */
    void update(Dish dish);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId};")
    List<Dish> findByCategory(Integer categoryId);
}
